package com.niit.cms.controller;

import com.niit.cms.entity.Order;
import com.niit.cms.entity.Orderdetail;
import com.niit.cms.service.CourseService;
import com.niit.cms.service.OrderService;
import com.niit.cms.service.OrderdetailService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: cao_jiaqi
 * @CreateTime： 2022/7/3 19:55
 */
@Controller
public class OrderController {
    @Resource
    private OrderdetailService orderdetailService;
    @Resource
    private OrderService orderService;
    @Resource
    private CourseService courseService;
    /**
     * @Description: 订单详情页
     * @Author: cao_jiaqi
     * @CreateTime: 2022/7/4 9:51
     * @param: model
     * @param: oid
     * @return: java.lang.String
     **/
    @GetMapping("/orderdetail")
    public String orderdetail(Model model, @RequestParam("oid") Integer oid){
        //查询该订单
        Order order = orderService.queryById(oid);
        model.addAttribute("order", order);
        //查询该订单订单详情
        List<Orderdetail> orderdetailList = orderdetailService.queryListByOid(oid);
        for(Orderdetail orderdetail : orderdetailList){
            orderdetail.setCourse(courseService.queryById(orderdetail.getCourseId()));
        }
        model.addAttribute("odlist", orderdetailList);
        return "cart_pay";
    }
}
